package com.jifeng.sterilizer.controller;

import java.util.Arrays;
import java.util.Map;

import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.R;
import com.jifeng.sterilizer.vo.ControllerEntityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jifeng.sterilizer.entity.ControllerEntity;
import com.jifeng.sterilizer.service.ControllerService;



/**
 * 中控机表
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-07-26 15:15:14
 */
@RestController
@RequestMapping("sterilizer/controller")
public class ControllerController {
    @Autowired
    private ControllerService controllerService;

    /**
     * 获取中控器的详情信息 PC
     */
    @GetMapping("/pc/detail")
    public R getDetail(@RequestParam Map<String, Object> params){
        R rs= controllerService.getDetail(params);
        return rs;
    }

    /**
     * 获取所有中控器地理位置信息
     */
    @GetMapping("/pc/map/list")
    public R mapList(){
        R rs= controllerService.mapList();
        return rs;
    }

    /**
     * 设置中控机的销售时间
     */
    @PostMapping("/pc/management/changeTime")
    public R changeTime(@RequestBody Map<String, Object> params){
        R rs= controllerService.changeTime(params);
        return rs;
    }
    /**
     * 删除中控器
     */
    @PostMapping("/pc/management/del")
    public R del(@RequestBody Map<String, Object> params){
        R rs= controllerService.del(params);
        return rs;
    }

    /**
     * 修改中控器的基本信息
     */
    @PostMapping("/pc/management/update")
    public R update(@RequestBody Map<String, Object> params){
        R rs= controllerService.myUpdate(params);
        return rs;
    }

    /**
     * 新增中控器的基本信息
     */
    @PostMapping("/pc/management/add")
    public R save(@RequestBody Map<String, Object> params){
        R rs= controllerService.add(params);
        return rs;
    }


    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = controllerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ControllerEntity controller = controllerService.getById(id);

        return R.ok().put("controller", controller);
    }

    // 获取中控器状态
    @GetMapping("/getInfo")
    public R getInfo(@RequestParam Map<String, Object> params){
        R rs = controllerService.getInfo(params);

        return rs;
    }

    // 获取中控器状态 微信小程序
    @GetMapping("/wx/getInfo")
    public R getWXInfo(@RequestParam Map<String, Object> params){
        R rs = controllerService.getWXInfo(params);

        return rs;
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody ControllerEntityVo controller){
		R rs= controllerService.mySave(controller);
        return rs;
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody ControllerEntityVo controller){
        R rs= controllerService.updateByNumber(controller);
        return rs;
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		controllerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
